home *** CD-ROM | disk | FTP | other *** search
- /*
- Commodore 64 Emulator v0.4 Earle F. Philhower III
- Copyright (C) 1993-4 (st916w9r@dunx1.ocs.drexel.edu)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- #include "Processor.h"
- #include "Memory.h"
- #include "Error.h"
- #include "Resources.h"
- #include "Preferences.h"
-
- byte VICText[1024], VICRegister[0x2f];
- word VICAddrBase, VICScreenPage, VICCharBase;
- byte VICBank, *VICCharDefs;
-
- Rect colorWindRect, bwWindRect, colorFullRect, bwFullRect;
-
- static int colorInitialized=0;
-
- WindowPtr BWVICWind;
- CWindowPtr ColorVICWind;
-
- void VICAddrAdjust()
- {
- VICBank=(RAM[0xdd00]&3)^3;
- VICAddrBase=VICBank*16384;
- VICScreenPage=((RAM[0xd018]&0xf0)>>4)*0x0400+VICAddrBase;
- VICCharBase=((RAM[0xd018]&0x0e)*1024);
- if ((VICBank==1)||(VICBank==3))
- VICCharDefs=RAM+(VICAddrBase+VICCharBase);
- else
- if (VICCharBase==4096) VICCharDefs=charROM;
- else if (VICCharBase==6144) VICCharDefs=charROM+0x0800;
- else VICCharDefs=RAM+(VICAddrBase+VICCharBase);
- }
-
- byte NotSameVIC()
- {
- register byte addr;
- register byte *ramRegister;
- register byte *vicRegister;
-
- ramRegister=&RAM[0xd000];
- vicRegister=&VICRegister[0];
-
- for (addr=0; addr<0x2f; addr++)
- {
- if (addr==0x11)
- {
- if ((*ramRegister++ & 127) != (*vicRegister++ & 127)) return 1;
- }
- else if (addr==0x12);
- else if (*ramRegister++ != *vicRegister++) return 1;
- }
- return 0;
- }
-
-
-
- void TotalRedrawVIC()
- {
- register byte addr;
-
- for (addr=0; addr<0x2f; addr++)
- VICRegister[addr]=RAM[0xd000+addr];
- VICAddrAdjust();
-
-
- if ((globalPref.colorVIC==0)||(colorInitialized==0)) BWTotalRedrawVIC();
- else ColorTotalRedrawVIC();
- }
-
- void RedrawVIC()
- {
- if (NotSameVIC())
- {
- TotalRedrawVIC();
- return;
- }
- VICAddrAdjust();
-
- if ((globalPref.colorVIC==0)||(colorInitialized==0)) BWRedrawVIC();
- else ColorRedrawVIC();
- }
-
- int VICInitialize()
- {
- int err;
-
- if (err=BWVICInitialize()!=kNoError) return err;
- err=ColorVICInitialize();
- if (err==kNoColorSupport)
- {
- colorInitialized=0;
- err=kNoError;
- }
- else
- {
- colorInitialized=1;
- err=kNoError;
- }
-
- return err;
- }
-
- void SetVICTitle(Str255 str)
- {
- SetWTitle(BWVICWind, str);
- if (colorInitialized) SetWTitle((WindowPtr)ColorVICWind, str);
- }
-
- void ShowVICWindow()
- {
- if (globalPref.doubleSize==1)
- {
- colorWindRect.top = colorFullRect.top * 2;
- colorWindRect.bottom = colorFullRect.bottom * 2;
- colorWindRect.left = colorFullRect.left * 2;
- colorWindRect.right = colorFullRect.right * 2;
-
- bwWindRect.top = bwFullRect.top * 2;
- bwWindRect.bottom = bwFullRect.bottom * 2;
- bwWindRect.left = bwFullRect.left * 2;
- bwWindRect.right = bwFullRect.right * 2;
- }
- else
- {
- colorWindRect=colorFullRect;
- bwWindRect=bwFullRect;
- }
-
- if (colorInitialized)
- SizeWindow((WindowPtr)ColorVICWind, colorWindRect.right-colorWindRect.left,
- colorWindRect.bottom-colorWindRect.top, true);
- SizeWindow(BWVICWind, bwWindRect.right-bwWindRect.left, bwWindRect.bottom-bwWindRect.top, true);
-
-
- if ((globalPref.colorVIC==0)||(colorInitialized==0))
- {
- if (colorInitialized) HideColorVIC();
- ShowBWVIC();
- }
- else
- {
- HideBWVIC();
- ShowColorVIC();
- }
- TotalRedrawVIC();
- }
-
- void DragVICWindow(EventRecord *event)
- {
- GrafPtr gp;
- Point x;
- WindowPtr theWind;
- extern Rect dragRect;
-
- FindWindow(event->where, &theWind);
- DragWindow(theWind, event->where, &dragRect);
-
- if (globalPref.byteAlign!=0)
- {
- GetPort(&gp);
- SetPort(theWind);
- x.h=x.v=0;
- LocalToGlobal(&x);
- x.h&=0xfff8;
- MoveWindow(theWind, x.h, x.v, TRUE);
- SetPort(gp);
- }
-
- GetPort(&gp);
- SetPort(theWind);
- x.h=x.v=0;
- LocalToGlobal(&x);
- MoveWindow(BWVICWind, x.h, x.v, TRUE);
- if (colorInitialized) MoveWindow((WindowPtr)ColorVICWind, x.h, x.v, TRUE);
- if (globalPref.colorVIC==0) SelectWindow(BWVICWind);
- SetPort(gp);
- }